package com.ycx.furns.web;

import com.ycx.furns.entity.Manager;
import com.ycx.furns.service.ManagerService;
import com.ycx.furns.service.impl.ManagerServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/managerServlet")
public class ManagerServlet extends BasicServlet{
    ManagerService managerService = new ManagerServiceImpl();

    protected void login(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String name = req.getParameter("user-name");
        String password = req.getParameter("user-password");

        Manager manager = managerService.managerLoginCheck(new Manager(null, name, password, null));
        if(manager != null){
            System.out.println("管理员 "+  name  +" 登陆成功");
            req.getSession().setAttribute("admin", "admin");
            req.getRequestDispatcher("/views/manage/manage_menu.jsp").forward(req, resp);
        }else {
            System.out.println("用户名 "+  name  +" 登陆失败");
            req.setAttribute("msg", "用户名或密码错误");
            req.getRequestDispatcher("/manage_login.jsp").forward(req, resp);
        }
    }
}
